<template>
    <div class="office">
        <officeOperation :option="option" v-if="officeshow"></officeOperation>
    </div>
</template>
<script>
import officeOperation from '../../components/OnlyOffice.vue'
import officeApi from "../../api/office"

export default {
    components: {
        officeOperation
    },
    data() {
        return {
            officeshow: false,
            id: this.$route.params.id,
            flag : this.$route.params.flag,
            //参考vabOnlyOffice组件参数配置
            option: {
                lang: 'zh-CN',//中文
                isPrint: false,//不懂 什么输出
                url: '',//后端返回nginx下载路径
                isEdit: false,//是否编辑 是编辑还是预览
                title: '',//标题
                key: '',//文件id ware 
                fileType: '',//文件类型
                user: { id: '', name: '' },//从后端那当前请求的用户和姓名
                editUrl: ''//回调接口 这个可以直接HTTP
            },
        }
    },
    created() {
        this.editOffice()
    },
    methods: {
        editOffice() {
            let params = {
                'warehouseId': this.id,
                'flag': this.flag
            }
            officeApi.editOffice(params).then(res => {
                if (res.data.code == 0) {
                    this.$message.error(res.data.msg)
                } else {
                    this.officeshow = true // 显示officeOperation组件
                    console.log("回调参数",res)
                    console.log(this.id)
                    this.option.key = this.id
                    this.option.isEdit = JSON.parse(this.flag)//在编辑方法里面就直接改为true
                    this.option.fileType = res.data.data.fileType
                    this.option.url = res.data.data.url
                    this.option.user.id = res.data.data.userId
                    this.option.user.name = res.data.data.name
                    this.option.title = res.data.data.title
                    this.option.editUrl = res.data.data.editUrl+"?id="+this.id//+"&filename="+this.option.title
                    console.log("最终参数",this.option.isEdit);
                }
            })
            .catch((err) => { // 捕获错误并显示错误消息
                console.error(err);
                this.$message.error('发生错误，请重试！');
            });
        }
    }

}

</script>
<style scoped="scoped">
.office {
  height: 100vh;
}
</style>